import request from "@/utils/request.js"
import store from '../store'

export const uploadURL = 'https://up-z2.qiniup.com/'
export const myURL = 'https://img.lesslesson.com/'

export async function uploadFile(file) {
    let token = await store.dispatch('getUpToken')
    let config = {
        headers: { 'Content-Type': 'multipart/form-data' }
    };
    let data = new FormData();
    data.append('token', token);     //七牛需要的token，叫后台给，是七牛账号密码等组成的hash
    data.append('file', file);
    return new Promise(resolve => {
        request.post(uploadURL, data, config).then(res => {
            resolve(myURL + res.key)
        })
    })
}